package com.r2coding.server.common.utils;

import com.r2coding.core.constants.Constants;

import java.util.Objects;

/**
 * @author 98k灬
 * @version v1.0.0
 * @Description : 分享ID存储工具类
 * @Create on : 2023/11/4 11:15
 **/
public class ShareIdUtil {
    private static ThreadLocal<Long> threadLocal = new ThreadLocal<>();

    /**
     * 设置当前线程的分享ID
     *
     * @param shareId 分享ID
     */
    public static void set(Long shareId) {
        threadLocal.set(shareId);
    }

    /**
     * 获取当前线程的分享ID
     *
     * @return 分享ID
     */
    public static Long get() {
        Long shareId = threadLocal.get();
        if (Objects.isNull(shareId)) {
            return Constants.ZERO_LONG;
        }
        return shareId;
    }
}
